package com.yanqu.road.server.logic.activity.condition.rank;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.task.args.ConsumeItemArgs;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.activity.BaseActivityData;
import com.yanqu.road.server.logic.activity.condition.BaseRankActivityCondition;

/**
 * 消耗冲榜 冲榜活动
 */
public class ConsumeItemRankCondition extends BaseRankActivityCondition {

	public ConsumeItemRankCondition(ActivityInfo activityInfo, ActivityConditionInfo activityConditionInfo, BaseActivityData baseActivityData) {
		super(activityInfo, activityConditionInfo, baseActivityData);
	}

	@Override
	public void addTrigger(GamePlayer player) {
		player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.ConsumeItemRank.getValue(), handle);
	}

	@Override
	public void removeTrigger(GamePlayer player) {
		player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.ConsumeItemRank.getValue(), handle);
	}

	@Override
	protected void player_BoardLevelHandle(Object object) {
		ConsumeItemArgs args = (ConsumeItemArgs)object;
		if(args.getGoodsId() == activityConditionInfo.getParamList().get(2).intValue()){
			setValue(getValue().add(args.getCount()));
			//重新生成排行榜
			rankChange();
		}
	}
}
